package com.cmccgz.udacs_landlord_webapp.main.test;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.cmccgz.baselibrary.view.CirclePageIndicator;
import com.cmccgz.udacs_landlord_webapp.R;

/**
 * 引导页
 */
public class GuideActivity extends AppCompatActivity {


    private ViewPager mPager;
    private int[] mGuideImages = {R.mipmap.guide1, R.mipmap.guide2, R.mipmap.guide3, R.mipmap.guide4};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);

        mPager = (ViewPager) findViewById(R.id.guide_viewpager);
        GuideFragmentPagerAdapter adapter = new GuideFragmentPagerAdapter(getSupportFragmentManager());
        mPager.setAdapter(adapter);

        CirclePageIndicator mIndicator = (CirclePageIndicator) findViewById(R.id.guide_indicator);
        mIndicator.setViewPager(mPager);
    }


    public class GuideFragmentPagerAdapter extends FragmentPagerAdapter {

        private Fragment[] mFragment;

        public GuideFragmentPagerAdapter(FragmentManager fm) {
            super(fm);
            mFragment = new Fragment[mGuideImages.length];
        }

        @Override
        public Fragment getItem(int position) {
            if (mFragment[position] == null) {
                Bundle data = new Bundle();
                data.putInt("imageId",mGuideImages[position]);

                mFragment[position] = new GuideFragment();
                mFragment[position].setArguments(data);
            }
            return mFragment[position];
        }

        @Override
        public int getCount() {
            return mGuideImages.length;
        }
    }

}
